//
//  GFTabBar.m
//  youkan
//
//  Created by 吴高烽 on 2017/11/12.
//  Copyright © 2017年 Honsintech. All rights reserved.
//

#import "GFTabBar.h"

@interface GFTabBar()


@end

@implementation GFTabBar

/** 给子控件进行布局 */
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat btnX = 0;
    CGFloat btnY = 0;
    CGFloat w = self.bounds.size.width;
    CGFloat h = kTabbarHeight;
    //!>    self.items 是将系统自带的传过来的
    CGFloat btnW = self.bounds.size.width/(self.items.count+1);
    CGFloat btnH = kTabbarHeight;
   /**
    for (UIView *tabBarButton in self.buttons) {
        if (i==2) {//!> 跳过中间的加号按钮
            i=3;
        }
        btnX = i*btnW;
        tabBarButton.frame =CGRectMake(btnX, btnY, btnW, btnH);
        i++;
    }*/
         NSInteger i=0;
         for (UIView *tabBarButton in self.subviews) {
             if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
                 if (i==2) {
                     i++;
                 }
                 btnX = i*btnW;
                 tabBarButton.frame =CGRectMake(btnX, btnY, btnW, btnH);
                 i++;
             }
         }
    self.plusButton.center =CGPointMake(w*0.5, h*0.5);
}

-(UIButton *)plusButton{
    if (!_plusButton) {
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_background_icon_add"] forState:UIControlStateSelected];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        // 默认按钮的尺寸跟背景图片一样大
        // sizeToFit:默认会根据按钮的背景图片或者image和文字计算出按钮的最合适的尺寸
        //            self.plusButton.bounds =CGRectMake(0, 0, self.plusButton.currentBackgroundImage.size.width, self.plusButton.currentBackgroundImage.size.height);
        [btn sizeToFit];
        _plusButton =btn;
        
        [self addSubview:_plusButton];
    }
    return _plusButton;
}

@end
